
class OrderDataModel {
  int code;
  String msg;
  OrderListModel? data;

  OrderDataModel({
    this.code = 0,
    this.msg = "",
    this.data,
  });

  factory OrderDataModel.fromJson(Map<String, dynamic> json) {
    return OrderDataModel(
      code: json['code'] ?? 0,
      msg: json['msg'] ?? "",
      data: json['data'] != null
          ? OrderListModel.fromJson(json['data'])
          : null,
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'code': code,
      'msg': msg,
      'data': data?.toJson(),
    };
  }
}

class OrderListModel {
  List<OrderArrayModel> list;

  OrderListModel({this.list = const []});

  factory OrderListModel.fromJson(Map<String, dynamic> json) {
    return OrderListModel(
      list: (json['list'] as List<dynamic>?)
              ?.map((item) => OrderArrayModel.fromJson(item))
              .toList() ??
          [],
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'list': list.map((item) => item.toJson()).toList(),
    };
  }
}

class OrderArrayModel {
  int num;
  double paymentAmount;
  double priceFee;
  int spuId;
  String attrvalue;
  String createTime;
  String orderId;
  String pic;
  String spuName;
  String status; // 0待付款 1待发货 2待收货 6售后中 3已完成 4已取消 5已关闭 7售后完成
  String symbol;
  int? rechargeType; // 新增字段，可能是int类型，也可能是null

  OrderArrayModel({
    this.num = 0,
    this.paymentAmount = 0,
    this.priceFee = 0,
    this.spuId = 0,
    this.attrvalue = "",
    this.createTime = "",
    this.orderId = "",
    this.pic = "",
    this.spuName = "",
    this.status = "",
    this.symbol = "",
    this.rechargeType, // 初始化时可能是null
  });

  factory OrderArrayModel.fromJson(Map<String, dynamic> json) {
    return OrderArrayModel(
      num: json['num'] ?? 0,
      paymentAmount: json['paymentAmount'] ?? 0.0,
      priceFee: json['priceFee'] ?? 0.0,
      spuId: json['spuId'] ?? 0,
      attrvalue: json['attrvalue'] ?? "",
      createTime: json['createTime'] ?? "",
      orderId: json['orderId'] ?? "",
      pic: json['pic'] ?? "",
      spuName: json['spuName'] ?? "",
      status: json['status'] ?? "",
      symbol: json['symbol'] ?? "",
      rechargeType: json['rechargeType'], // 注意这里，可能是null
    );
  }

  Map<String, dynamic> toJson() {
    return {
      'num': num,
      'paymentAmount': paymentAmount,
      'priceFee': priceFee,
      'spuId': spuId,
      'attrvalue': attrvalue,
      'createTime': createTime,
      'orderId': orderId,
      'pic': pic,
      'spuName': spuName,
      'status': status,
      'symbol': symbol,
      'rechargeType': rechargeType, // 可以是null
    };
  }
}

class PaymentModel {
  int code;
  String msg;
  List<PayListModel> data;

  PaymentModel({
    this.code = 0,
    this.msg = '',
    this.data = const [],
  });

  factory PaymentModel.fromJson(Map<String, dynamic> json) {
    return PaymentModel(
      code: json['code'] ?? 0,
      msg: json['msg'] ?? '',
      data: (json['data'] as List<dynamic>?)
              ?.map((e) => PayListModel.fromJson(e))
              .toList() ??
          [],
    );
  }
}

class PayListModel {
  double fee;
  int shopPaymentId;
  String infor;
  String name;
  String pic;
  String tips;
  int status;
  int needAddress; // 0 不需要账单地址 1需要账单地址
  int localPayment; // 0是Credit & Debit Card,1是Local Payment

  PayListModel({
    this.fee = 0,
    this.shopPaymentId = 0,
    this.infor = '',
    this.name = '',
    this.pic = '',
    this.tips = '',
    this.status = 1,
    this.needAddress = 0,
    this.localPayment = 0,
  });

  factory PayListModel.fromJson(Map<String, dynamic> json) {
    return PayListModel(
      fee: (json['fee'] as num?)?.toDouble() ?? 0,
      shopPaymentId: json['shopPaymentId'] ?? 0,
      infor: json['infor'] ?? '',
      name: json['name'] ?? '',
      pic: json['pic'] ?? '',
      tips: json['tips'] ?? '',
      status: json['status'] ?? 1,
      needAddress: json['needAddress'] ?? 0,
      localPayment: json['localPayment'] ?? 0,
    );
  }

  // 添加 toJson 方法
  Map<String, dynamic> toJson() {
    return {
      'fee': fee,
      'shopPaymentId': shopPaymentId,
      'infor': infor,
      'name': name,
      'pic': pic,
      'tips': tips,
      'status': status,
      'needAddress': needAddress,
      'localPayment': localPayment,
    };
  }
}


class CashierModel {
  int code;
  String msg;
  CashierDataModel? data;

  CashierModel({
    required this.code,
    required this.msg,
    this.data,
  });

  factory CashierModel.fromJson(Map<String, dynamic> json) {
    return CashierModel(
      code: json['code'] ?? 0,
      msg: json['msg'] ?? '',
      data: json['data'] != null ? CashierDataModel.fromJson(json['data']) : null,
    );
  }
}

class CashierDataModel {
  String processFee;
  String symbol;
  String paymentMoney;
  int paymentMethod;

  CashierDataModel({
    required this.processFee,
    required this.symbol,
    required this.paymentMoney,
    required this.paymentMethod,
  });

  factory CashierDataModel.fromJson(Map<String, dynamic> json) {
    return CashierDataModel(
      processFee: json['processFee'] ?? '',
      symbol: json['symbol'] ?? '',
      paymentMoney: json['paymentMoney'] ?? '',
      paymentMethod: json['paymentMethod'] ?? 0,
    );
  }
}
